package com.decent.web.system.dao;

import com.decent.web.system.dto.PayOrderDTO;
import com.decent.web.system.dto.SystemOrderDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/**
 * @author: decent Gjh
 * @date: 2022/10/29/16:22
 * @description:
 */
@Mapper
public interface WebUserDao {
    /**
     * 获取用户余额
     * @param id 用户id
     * @return 余额
     */
    @Select("select money from web_user where id = #{id}")
    BigDecimal getUserMoney(@Param("id") int id);

    /**
     * 支付
     * @param createOrderDTO 用户信息
     * @param systemOrderDTO 订单信息
     * @return 影响行数
     */
    @Update("UPDATE web_user SET money = money-#{order.totalPrice} WHERE id = #{user.userId} and money >= #{order.totalPrice};")
    int payOrder(@Param("user") PayOrderDTO createOrderDTO,@Param("order") SystemOrderDTO systemOrderDTO);
}
